home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / gui / gui4cli.lha / Gui4Cli / Tools / Read.gc < prev    next >
Text File  |  1998-10-22  |  5KB  |  211 lines

  1. G4C
  2.  
  3. ; A File Reader.
  4. ; USE: GUILOAD guis:tools/read.gc FileName
  5.  
  6. ; ======================================================================
  7. ;               Globals & system events
  8. ; ======================================================================
  9.  
  10. WinBig 0 11 0 -13 "Loading..."    ; you may want to change the position
  11. WinType 11110001
  12. Varpath 'read.pop/read.srch'      ; use private vars & 2 other guis vars
  13.  
  14. xOnLoad filename
  15. filepath = ''
  16. gosub read.gc startup
  17.  
  18. xOnReload filename
  19. filepath = ''
  20. gosub read.gc startup
  21.  
  22. xROUTINE startup
  23. guiopen read.gc
  24. if $filename > ' '
  25.    ; OK file was passed
  26. elseif $*FILENAME > ' '         ; Global *FILENAME is for compatibility
  27. andifexists file $*FILENAME     ; with older versions.
  28.    filename  = $*FILENAME
  29.    delvar *FILENAME
  30. else
  31.    gosub read.gc getfile
  32. endif
  33. gosub read.gc filechange
  34. extract filename path filepath
  35.  
  36.  
  37. ;-------> Upon closing, we quit so as not to use-up memory
  38.  
  39. xOnClose
  40. guiquit read.gc
  41.  
  42. ;------> on RMB we open our pop-up command window
  43.  
  44. xOnRMB 
  45. guiopen Read.pop
  46.  
  47. ;------> on quitting we also quit our other 2 guis
  48.  
  49. xonquit
  50. guiquit  read.srch
  51. guiquit  read.pop
  52.  
  53. ; ======================================================================
  54. ;               The listview
  55. ; ======================================================================
  56.  
  57. xListview 0 0 0 0 "" var "" 20 MULTI
  58. GadID  1
  59. ; GadFont #mono 8 000
  60. ; ATTR lvstyle 2031   ; uncomment this to get 3D letters
  61. ATTR lvlinedist 2     ; This will set the distance between lines
  62.  
  63. ; ======================================================================
  64. ;               Routines
  65. ; ======================================================================
  66.  
  67. ;------> Routine to load & show file
  68.  
  69. xRoutine filechange filename            ; routine to load & show file
  70. if $filename > ' '
  71.    guiscreen read.gc front
  72.    SetWinTitle read.gc "Loading...."
  73.    lvuse read.gc 1                      ; choose our display listview
  74.    LVChange $filename
  75.    SetWinTitle read.gc '$filename                                '
  76. endif
  77. stop
  78.  
  79. ;------------> open a requester and get a file
  80.  
  81. xroutine getfile
  82. newname = ""
  83. ReqFile -1 -1 250 200 "Choose file" LOAD newname $filepath
  84. if $newname > ""
  85.    filename = $newname
  86.    extract filename path filepath
  87.    gosub read.gc filechange
  88. endif
  89.  
  90.  
  91. ;######################################################################
  92.                 NEWFILE read.pop
  93. ;               Popup on RMB gui
  94. ;######################################################################
  95.  
  96.  
  97. WINBIG 341 87 80 90 ""
  98. WinType 00001000
  99. winonmouse 30 7 
  100. varpath read.gc         ; use our main gui's vars
  101. box 0 0 0 0 out button
  102.  
  103. xOnRMB 
  104. guiclose Read.pop
  105.  
  106. xOnInactive
  107. guiclose Read.pop
  108.  
  109. xOnFail
  110. ezreq "Error during operation" OK ""
  111.  
  112. ;---------------> the Buttons
  113.  
  114. XBUTTON 0 0 80 15 Open
  115. guiclose Read.pop
  116. extract filename path read.gc/filepath
  117. ; use new filereq gui
  118. guiload guis:tools/filereq.gc read.gc filechange $read.gc/filepath 
  119. ; gosub read.gc getfile
  120.  
  121. XBUTTON 0 15 80 15 Edit
  122. guiclose Read.pop
  123. ifexists gui cedbar.gc                  ; This is for CEd (long story..)
  124.    guiscreen cedbar.gc front
  125.    sendrexx rexx_ced 'open new'
  126.    sendrexx rexx_ced 'open $filename'
  127.    sendrexx rexx_ced 'expand view'
  128. elseifexists variable *DEF.EDITOR
  129.    run '$*DEF.EDITOR $filename'         ; if called from a file manager
  130. else
  131.    run 'c:ed $filename'                 ; use ed if nothing defined
  132. endif
  133.  
  134. XBUTTON 0 30 80 15 Search
  135. guiclose read.pop
  136. guiopen  read.srch
  137.  
  138. XBUTTON 0 45 80 15 'Delete'
  139. action delete $filename req
  140.  
  141. XBUTTON 0 60 80 15 Quit
  142. guiclose read.pop
  143. guiquit  read.gc
  144.  
  145. ; set tb size..
  146.  
  147. XHSLIDER 1 75 37 14 "" tab 0 10 8 "%ld"
  148.  
  149. XBUTTON 58 75 22 14 "T"
  150. set tab $tab
  151. guiclose read.pop
  152. lvuse read.gc 1        ; reload listview
  153. LVChange $filename
  154.  
  155.  
  156. ;######################################################################
  157.                 NEWFILE read.srch
  158. ;               Gui to Search the file
  159. ;######################################################################
  160.  
  161.  
  162. winbig -1 -1 300 32 'Enter Search string :'
  163. wintype 11110001
  164. varpath ''
  165.  
  166. xonopen         ; reset variables on opening
  167. mode = CI
  168. flag = 0
  169.  
  170. xTextIn  0 0 0 15 '' str '' 128
  171. gosub read.srch search
  172.  
  173. xCycler  0 17 150 14 '' mode    ; choose case sensitive/insen..
  174. cstr 'Ignore case' CI
  175. cstr 'Same case'   CS
  176.  
  177.  
  178. xButton 150 17 100 14 'Top'     ; go to top of lv
  179. flag = 0                        
  180. lvgo #0
  181. update read.gc 1 0
  182. setwintitle read.srch 'Enter search string :'
  183.  
  184.  
  185. xButton  250 17 50 14 >>
  186. gosub read.srch search
  187.  
  188.  
  189. xroutine search
  190. if $str = ''            ; no string entered 
  191.    stop
  192. endif
  193. lvuse read.gc 1         ; use the reader's listview
  194. if $flag = 0            ; flag=0 means this is the first time
  195.    flag = 1
  196.    lvsearch $str $mode first    ; Keywords such as mode (CI or CS), do
  197.                                 ; not get translated, but in lvsearch
  198.                                 ; it's an exception, so we can say $mode
  199. else
  200.    lvsearch $str $mode next
  201. endif
  202. if $$lv.line > ''               ; update to line found
  203.    update read.gc 1 $$lv.line
  204.    setwintitle read.srch 'Line $$lv.line'
  205. else
  206.    lvgo #0                      ; or else go top again
  207.    flag = 0
  208.    setwintitle read.srch 'Search Finished'
  209. endif
  210.  
  211.